#pragma once
#include <iostream>
#include <string>
#include"Log.hpp"

using namespace std;

enum{
    DivZero=1,
    ModZero,
    Unknown
};

extern Log lg;

class Task
{
public:
    Task(int sockfd, const std::string &clientip, uint16_t clientport)
    :_sockfd(sockfd)
    ,_clientip(clientip)
    ,_clientport(clientport)
    {}

    Task()
    {}
    void run()
    {
        char buffer[4096];
        ssize_t n = read(_sockfd, buffer, sizeof(buffer));
        if(n < 0)
        {
            lg(Waring, "read failed, errno: %d", errno);
        }
        else if(n == 0)
        {
            lg(Info, "%s:%d quit, server close sockfd: %d", _clientip.c_str(), _clientport, _sockfd);
        }
        buffer[n] = 0;
        cout<<"client say#"<<buffer<<endl;
        string echo_string = "tcpserver echo#";
        echo_string += buffer;

        write(_sockfd, echo_string.c_str(), echo_string.size());
    }
    void operator ()()
    {
        run();
    }
    std::string GetResult()
    {
        
    }
    std::string GetTask()
    {
       
    }
    ~Task()
    {
    }

private:
    int _sockfd;
    std::string _clientip;
    uint16_t _clientport;
};